<?php
/**
 * appRain CMF
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */
$titleadditional =   isset($file2edit) ? "({$file2edit})":"";
$ext_class = isset( $file2editcontent ) ? 'displaynone"' :"";
?>
<form method="post" class="app_form frm_editor">
    <?php App::Helper('Toolbar')->setTitle("Editor {$titleadditional}"  )->setBtnToggle(array("name"=>"Browse Directory"))->setBtnBack()->Render(array('code'=>'code_editor_edit_top'));?>

    <div id="hidden_content" class="<?php echo $ext_class; ?>" style="margin-bottom:20px">
    <?php
        $pathback = substr($base_path,0,strrpos($base_path,'/'));
        $data[] = array(App::load("Helper/Html")->linkTag($this->baseurl('/developer/editor/' . base64_encode( $pathback )),'Back'),

        App::load("Helper/Html")->linkTag($this->baseurl('/developer/editor/' . base64_encode( $pathback )),App::load("Helper/Html")->imgTag($this->baseurl('/images/admin/back.gif'))));

        $Grid = App::Module('DataGrid')->setHeader(Array($this->__('Name'),$this->__('Options')));

        if( !empty($dir_listing['dir']))
        {
            foreach( $dir_listing['dir'] as $key => $val )
            {
                $name = $val["name"];
                $type = $val["type"];
                $Grid->addRow( ' <a href="' . $this->baseurl('/') . 'developer/editor/' . base64_encode( $base_path . '/' . $name ) .  '">'. $name . '</a></label>',
                                ' <a href="' . $this->baseurl('/') . 'developer/editor/' . base64_encode( $base_path . '/' . $name ) .  '"><img src="' . $this->baseurl('/') . '/images/admin/folder.gif" title="Enter" alt="Enter" /></a></label>'
                                );
            }
        }

        if( !empty($dir_listing['file']))
        {
            foreach( $dir_listing['file'] as $key => $val )
            {
                $base_path = ( $base_path != "") ? $base_path : "/";
                $name = $val["name"];
                $type = $val["type"];
                $Grid->addRow( '<label><a href="' . $this->baseurl('/') . 'developer/editor/' . base64_encode( $base_path ) .  '/' . base64_encode($name) . '">' . $name .'</a></label>','<label><a href="' . $this->baseurl('/') . 'developer/editor/' . base64_encode( $base_path ) .  '/' . base64_encode($name) . '"><img src="' . $this->baseurl('/') . '/images/admin/edit.gif" title="Edit ' . $val['name'] .  '" alt="Edit" /></a></label>');
            }
        }

        if( !empty($data) ) $Grid->Render();
        else echo $this->callElement('common/message', array('caption' =>'Message','type' => 'error', 'message' => 'No Data found for Account'));
    ?>
    </div>

    <?php
		if(isset($file2editcontent)){

			echo App::load("Helper/Html")->textareaTag("data[Editor][content]",htmlspecialchars($file2editcontent),array("wrap"=>"off","class"=>"lined","rows" => "30","style"=>"width:99%"));
		}
	?>

    <?php App::Helper('Toolbar')->setBtnSave()->setBtnBack()->setBtnCustomHTML('<span class="message" style="float:right;display:block;width:200px;height:15px;">&nbsp;&nbsp;&nbsp;</span>')->Render(array('code'=>'code_editor_edit_bottom')); ?>
</form>
<?php  App::Helper('JavaScript')->setAjax(array("debug"=>false,"autoHide"=>false))->appForm('.frm_editor');?>
<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery(".view_hidden_content").live("click", function(e){
            if(jQuery("#hidden_content").css("display") == "block")
            {
                jQuery("#hidden_content").css("display", "none");
            }
            else
            {
                jQuery("#hidden_content").css("display", "block");
            }
        });
    });
</script>